import request from "@/utils/request";
// 登录
export const loginApi = (data) => {
  return request({
    url: "/login",
    method: "POST",
    data,
  });
};

// 获取菜单
export const getMenuInfoApi = () => {
  return request({
    method: "GET",
    url: "/menus",
  });
};
// 获取用户列表
export const getUserListApi = (data) => {
  return request({
    method: "GET",
    url: "/users",
    params: data,
  });
};
// 修改用户状态
export const userStateChangeApi = (id, mg_state) => {
  return request({
    method: "PUT",
    url: `/users/${id}/state/${mg_state}`,
  });
};
// 添加新用户
export const addUserApi = (data) => {
  return request({
    method: "POST",
    url: "/users",
    data,
  });
};
// 获取用户个人信息
export const showEditApi = (id) => {
  return request({
    method: "GET",
    url: `/users/${id}`,
  });
};
// 修改用户信息
export const changeEditApi = (id, data) => {
  return request({
    method: "PUT",
    url: `/users/${id}`,
    data,
  });
};
// 删除单个用户
export const delUserApi = (id) => {
  return request({
    method: "DELETE",
    url: `/users/${id}`,
    data: {
      id,
    },
  });
};
// 获取权限列表
export const getRightsListApi = (data) => {
  return request({
    method: "GET",
    url: "/rights/list",
    data,
  });
};
// 获取角色列表
export const getRolesListApi = (data) => {
  return request({
    method: "GET",
    url: "/roles",
    data,
  });
};
// 删除权限
export const delRolesApi = (roleId, rightId) => {
  return request({
    method: "DELETE",
    url: `/roles/${roleId}/rights/${rightId}`,
  });
};
// 分配角色权限列表
export const setRolesListApi = (data) => {
  return request({
    method: "GET",
    url: "/rights/tree",
    data,
  });
};
// 分配角色权限
export const allotRolesRightsApi = (id, data) => {
  return request({
    method: "POST",
    url: `/roles/${id}/rights`,
    data,
  });
};
// 分配角色
export const saveRolesApi = (id, data) => {
  return request({
    method: "PUT",
    url: `users/${id}/role`,
    data,
  });
};

/*********************  商品分类 **********************/
// 获取商品分类列表
export const getCateListApi = (params) => {
  return request({
    method: "GET",
    url: "/categories",
    params,
  });
};
// 添加分类
export const addCateApi = (data) => {
  return request({
    method: "POST",
    url: "/categories",
    data,
  });
};
/*********************  商品列表 **********************/
export const getGoodsListApi = (params) => {
  return request({
    method: "GET",
    url: "/goods",
    params,
  });
};
export const delGoodsApi = (id) => {
  return request({
    method: "DELETE",
    url: `/goods/${id}`,
  });
};
/*********************  添加商品 **********************/
export const getAddGoodsParamsApi = (id, params) => {
  return request({
    method: "GET",
    url: `/categories/${id}/attributes`,
    params,
  });
};

export const getAddParamsApi = (id, data) => {
  return request({
    method: "POST",
    url: `/categories/${id}/attributes`,
    data,
  });
};

export const addGoodsApi = (data) => {
  return request({
    method: "POST",
    url: "/goods",
    data,
  });
};
/*********************  获取订单列表 **********************/
export const getOrdersListApi = (params) => {
  return request({
    method: "GET",
    url: "orders",
    params,
  });
};
export const getOrderApi = (id) => {
  return request({
    method: "GET",
    url: `/orders/${id}`,
  });
};
export const subOrderApi = (id, data) => {
  return request({
    method: "PUT",
    url: `/orders/${id}`,
    data,
  });
};
export const getProgressInfoApi = (id) => {
  return request({
    method: "GET",
    url: `/kuaidi/${id}`,
  });
};
